package org.jash.shop;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class SplashActivity extends AppCompatActivity {
    private TextView count;
    private final Handler handler = new Handler(Looper.getMainLooper());
    public static final int TOTAL = 5;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        count = findViewById(R.id.count);
        for (int i = 0; i <= TOTAL ; i++) {
            String s = "倒计时" + (TOTAL - i) + "秒";
            handler.postDelayed(() -> count.setText(s), i * 1000);
        }
        handler.postDelayed(() -> {
            startActivity(new Intent(this, MainActivity.class));
            finish();
        }, (TOTAL + 1) * 1000);
        count.setOnClickListener(v -> {
            handler.removeCallbacksAndMessages(null);
            startActivity(new Intent(this, MainActivity.class));
            finish();
        });

    }
}